home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13227 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.7 KB  |  107 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Philippe Verdy <100105.3120@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Does Borland share these MSVC++ problems?
  5. Date: 24 Mar 1996 11:58:19 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4j3dcr$pd6@arl-news-svc-2.compuserve.com>
  8. NNTP-Posting-Host: dd22-055.compuserve.com
  9.  
  10. john@meenie.Princeton.EDU (John Saponara) s'Θcrit :
  11. > Folks,
  12. >  
  13. > As I was unable to wait long enough on the phone for Borland pre-sale
  14. > tech support (cannot afford to be on hold that long and that far away),
  15. > please let me know if Borland differs from MS Visual C++ in any of the
  16. > following traits (all of which have frustrated me regarding VC++). 
  17. > I have come to expect these features from using GNU C++, but must
  18. > diagnose a particular problem using a C++ compiler for PCs.
  19. >  
  20. > 1. Do index variables declared in the for statement persist after the loop?
  21. >
  22. No. index variables have local scope within the for loop body
  23. >
  24. > 2. Is there no `bool' builtin type?
  25. >
  26. Yes or no. Depending on the compiler implementation, bool may
  27. be a built-in type or a class type. Whatever the option, you
  28. should always include <bool.h> to get bool support.
  29. >  
  30. > 3. Must I return a value from a non-void function
  31. >    even in a branch that calls exit(1)?
  32. >
  33. Normally no. The compiler should contain a pragma declaration
  34. for the exit() function defined in <stdlib.h> that explicitly
  35. declares this function as either never returning or as having
  36. special flow control. The same applies to longjmp() and raise().
  37. Sometimes, this pragma is not supported by the compiler. The
  38. best thing to do is to always use an unconditional return
  39. statement at the end of your function, which should only be
  40. reached by normal cases when exit() is not called.
  41. >  
  42. > 4. Is there no list of candidate conversions to help
  43. >    me find the cause of the compiler error:
  44. >    `>' : 2 overloads have similar conversions
  45. >    (for various operators)?
  46. >
  47. Some compilers have more explicit messages to help you.
  48. However, avoid to write several conversion operators from
  49. your class definitions. Use only one for built-in scalars,
  50. else you will encounter many ambiguities.
  51. Refrain using conversions from a class object to a built-in
  52. pointer type (like char *, or void *).
  53. Example: you should not define a conversion from
  54. a class to a (char *), to allow simple streaming. Replace it
  55. with a public "const char * str() const" method, that you
  56. can use to implement a streaming operator like:
  57. "ostream & operator<< (ostream &os, const class A &object);"
  58. in the case you do not want this operator to be explicitly
  59. declared as a friend function.
  60. >  
  61. > 5. Are the POSIX functions (particularly sleep, link, unlink) unavailable?
  62. >
  63. No. You should include the appropriate include files for your
  64. platform. However, these are C linkage functions. So you can
  65. include these include files within a:
  66.   extern "C" {
  67.   #include <C-library.h>
  68.   ...
  69.   }
  70. if your system does not provide support for C++ in its header
  71. files.
  72. >  
  73. > 6. Is there no iostream extension that takes the same vararg list as printf()?
  74. >    In g++ you can write, for example: cout.form( "%s\n", charArray );
  75. >
  76. If it is missing, you can add it very simply in the ostream
  77. class definition:
  78. --- iostream.h -----
  79.   extern "C" {
  80.   #include <stdio.h>  // support for ANSI-C sprintf()
  81.   #include <stdarg.h> // support for ANSI-C va_*
  82.   };
  83.  
  84.   class ostream {
  85.   public:
  86.     ...
  87.     void form(const char *format, ...);
  88.   };
  89.   void ostream::form(const char *format, ...)
  90.   {
  91.     char *buffer[1024];
  92.     va_list args;
  93.  
  94.     va_start(format, args);
  95.     vsprintf(buffer, format, args);
  96.     va_end(args);
  97.     *this << buffer;
  98.   }
  99. >  
  100. > I don't want to incite flames, only to know which (if any)
  101. > of these problems Borland C++ shares with MS Visual C++.
  102. >  
  103. > Thanks,
  104. > John
  105. >  
  106.  
  107.